package com.ymatou.iapi.couponactivity.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponactivity.parameter.GetUserReceiveListBean;
import com.ymatou.iapi.couponactivity.parameter.UserReceiveInfo;
import com.ymatou.iapi.couponactivity.parameter.UserReceiveList;
import com.ymatou.iapi.couponactivity.service.GetUserReceiveListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtCouponActivityWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取用户领取失败的列表用例
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserReceiveList{
	private static GetUserReceiveListBean getuserreceivelistBean;
	private static GetUserReceiveListCall getuserreceivelistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户领取失败的列表用例");
	}

	@Before
	public void caseUp() {
		getuserreceivelistBean=new GetUserReceiveListBean();
		getuserreceivelistCall=new GetUserReceiveListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserreceivelistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserReceiveList_001() {
		Logger.start(true,"获取用户领取失败的列表");
		try {
			Map result = new YmtCouponActivityWapper().selectGetUserReceiveList().get(0);
			
			getuserreceivelistBean.setUserId(Integer.parseInt(result.get("UserId").toString()));
			
			getuserreceivelistCall.setData(getuserreceivelistBean);
			getuserreceivelistCall.callService();			
			
			List<Map> results = new YmtCouponActivityWapper().selectGetUserReceiveListByUserId(result.get("UserId").toString());
			
			Logger.verifyEquals("0", getuserreceivelistCall.getCode(), "验证返回StatusCode");
			Logger.verifyEquals("操作成功！", getuserreceivelistCall.getMessage(), "验证返回Message");
			
			UserReceiveList userReceiveList = getuserreceivelistCall.getUserReceiveList();
			
			List<UserReceiveInfo> userReceiveInfos=userReceiveList.getUserReceiveList();			
			
			Logger.verifyEquals(results.size(), userReceiveInfos.size(), "验证返回返回条数正常");
			
			for(int i=0;i<results.size();i++)
			{
				if(userReceiveInfos.get(i).getActivityName().toString().equals(""))
				{
					Logger.verifyIsNull(results.get(i).get("activityname"),"验证返回ActivityName与数据库相同");
				}
				else {
					Logger.verifyEquals(results.get(i).get("activityname"), userReceiveInfos.get(i).getActivityName().toString(), "验证返回ActivityName与数据库相同");
				}
						Logger.verifyEquals(results.get(i).get("BoundId"), userReceiveInfos.get(i).getBoundId(), "验证返回BoundId与数据库相同");
				Logger.verifyEquals(results.get(i).get("BoundCode"), userReceiveInfos.get(i).getBoundCode(), "验证返回BoundCode与数据库相同");
				Logger.verifyEquals(results.get(i).get("ActivityCode"), userReceiveInfos.get(i).getActivityCode(), "验证返回ActivityCode与数据库相同");
				Logger.verifyEquals(results.get(i).get("ActivitySequence"), userReceiveInfos.get(i).getActivitySequence(), "验证返回ActivitySequence与数据库相同");
				Logger.verifyEquals(results.get(i).get("UserId"), userReceiveInfos.get(i).getUserId(), "验证返回UserId与数据库相同");
				Logger.verifyEquals(results.get(i).get("MobilePhone"), userReceiveInfos.get(i).getMobilePhone(), "验证返回MobilePhone与数据库相同");
				Logger.verifyEquals(results.get(i).get("DeviceNumber"), userReceiveInfos.get(i).getDeviceNumber(), "验证返回DeviceNumber与数据库相同");
				Logger.verifyEquals(results.get(i).get("PreCouponCode"), userReceiveInfos.get(i).getPreCouponCode(), "验证返回PreCouponCode与数据库相同");
				Logger.verifyEquals(Integer.parseInt(results.get(i).get("CouponSendStatus").toString()), userReceiveInfos.get(i).getCouponSendStatus(), "验证返回CouponSendStatus与数据库相同");
				Logger.verifyEquals(Integer.parseInt(results.get(i).get("ExecuteTimes").toString()), userReceiveInfos.get(i).getExecuteTimes(), "验证返回ExecuteTimes与数据库相同");
				Logger.verifyEquals(results.get(i).get("FailErrorCode"), userReceiveInfos.get(i).getFailErrorCode(), "验证返回FailErrorCode与数据库相同");
				Logger.verifyEquals(results.get(i).get("FailErrorDetail"), userReceiveInfos.get(i).getFailErrorDetail(), "验证返回FailErrorDetail与数据库相同");

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}